package org.bigdata.framework.admin.web.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bigdata.framework.admin.web.util.CreateSecrteKey;
import org.bigdata.framework.admin.web.util.DBUtils;
import org.bigdata.framework.admin.web.util.DateUtils;
import org.bigdata.framework.admin.web.util.ExcelUtil;
import org.bigdata.framework.admin.web.util.FileDownloadUtil;
import org.bigdata.framework.admin.web.util.IPConvertHelper;
import org.bigdata.framework.admin.web.util.MD5;
import org.bigdata.framework.core.model.Classes;
import org.bigdata.framework.core.model.Department;
import org.bigdata.framework.core.model.Dict;
import org.bigdata.framework.core.model.DictItem;
import org.bigdata.framework.core.model.IpLoginNumber;
import org.bigdata.framework.core.model.Log;
import org.bigdata.framework.core.model.Member;
import org.bigdata.framework.core.model.ObjectProperty;
import org.bigdata.framework.core.model.OpenLogin;
import org.bigdata.framework.core.model.PayOrder;
import org.bigdata.framework.core.model.PayOrderDetail;
import org.bigdata.framework.core.model.PayRecharge;
import org.bigdata.framework.core.model.Payment;
import org.bigdata.framework.core.model.Project;
import org.bigdata.framework.core.model.RepositoryProduct;
import org.bigdata.framework.core.model.User;
import org.bigdata.framework.core.model.UserGroup;
import org.bigdata.framework.core.protocol.IBaseService;
import org.bigdata.framework.core.protocol.IDataHandlingService;
import org.bigdata.framework.core.protocol.IDynamicService;
import org.bigdata.framework.core.protocol.IPayService;
import org.bigdata.framework.core.protocol.IPublicService;
import org.bigdata.framework.core.protocol.ISearchService;
import org.bigdata.framework.core.protocol.IWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.xxl.conf.core.XxlConfClient;

@Controller
public class ApplicationController extends BaseContoroller {

	@Autowired
	private IBaseService baseService;
	@Autowired
	private IPublicService publicService;
	@Autowired
	private IDataHandlingService dataHandlingService;
	@Autowired
	private IWordService iWordService;
	@Autowired
	private IPayService payService;
	@Autowired
	private ISearchService searchService;
	@Autowired
	private IDynamicService dynamicService;

	// 公共日常记录
	public void log(Integer createUserId, String logType, String classesId, String dataId, String logText,
			Integer logStatus) throws Exception {
		// 获得本机IP
		InetAddress addr = InetAddress.getLocalHost();
		String createIpAddress = addr.getHostAddress();
		// 获得时间
		String createTime = DateUtils.getDateTime();

		Log log = new Log();
		log.setCreateTime(createTime);
		log.setCreateUserId(createUserId);
		log.setCreateIpAddress(createIpAddress);
		log.setLogType(logType);
		log.setLogText(logText);
		log.setLogStatus(logStatus);

		if (classesId != null) {
			log.setClassesId(classesId);
		}
		if (dataId != null) {
			log.setDataId(dataId);
		}
		baseService.saveLog(log);
	}

	// 知识库应用管理 -->知识库应用配置
	@RequestMapping("application-setting.html")
	public String toSetting() {

		return "/modules/application/application_setting";
	}

	// 知识库应用管理 -->专题管理
	@RequestMapping("application-special-manage.html")
	public ModelAndView toSpecialManage(HttpServletRequest request) {
		String ztreeId = request.getParameter("ztreeId");
		ModelAndView view = new ModelAndView();
		view.addObject("ztreeId", ztreeId);
		view.setViewName("/modules/pay/application_special_manage");
		return view;
		// return "/modules/pay/application_special_manage";
	}

	// 知识库应用管理 -->专题管理--添加
	@RequestMapping("application-special-manage-add.html")
	public String toSpecialManageAdd() {
		return "/modules/pay/application_special_manager_add";
	}

	// 知识库应用管理 -->专题管理--自定义专题数据
	@RequestMapping("application-special-data-queryspecial.html")
	public String toSpecialManageAddSpecialData() {
		return "/modules/pay/application_special_data_queryspecial";
	}

	// 增加专题树状
	@RequestMapping("application-special-manage-zTree.html")
	public String toApplicationSpecialManagezTree() {
		return "/modules/pay/application_special_manage_zTree";
	}

	// 知识库应用管理 -->知识库产品管理
	@RequestMapping("application-repository-product.html")
	public String toRepositoryProduct() {

		return "/modules/pay/application_repository_product";
	}

	// 知识库应用管理 -->知识库产品管理--添加
	@RequestMapping("application_repository_product_add.html")
	public String toRepositoryProductAdd() {

		return "/modules/pay/application_repository_product_add";
	}

	// 知识库产品添加字典
	@RequestMapping("application-repository-product-category.html")
	public String toApplicationRepositoryProductCategory() {

		return "/modules/pay/application_repository_product_category";
	}

	// 知识库应用管理 -->个人用户管理-->默认跳转 查询页面
	@RequestMapping("sso-user-member.html")
	public String toUserGuanLi() {
		return "/modules/sso/application_user_member";
	}

	// 知识库应用管理 -->个人用户管理-->查看详情
	@RequestMapping("application_user_select.html")
	public String toUserselect() {
		return "/modules/sso/application_user_select";
	}

	// 知识库应用管理 -->个人用户管理-->修改密码
	@RequestMapping("application_user_update_password.html")
	public String toUpdatePasswordUser() {
		return "/modules/sso/application_user_update_password";
	}

	// 知识库应用管理 -->个人用户管理-->更新 新增 页面
	@RequestMapping("application_user_add_update.html")
	public String toUserAddAndUpdate() {
		return "/modules/sso/application_user_add_update";
	}

	// 知识库应用管理 -->机构用户管理-->默认跳转 查询页面
	@RequestMapping("sso-organization-list.html")
	public String toMemberList() {
		return "/modules/application/application_organization_list";
	}

	// 知识库应用管理 -->机构用户管理--> 新增 更新页面
	@RequestMapping("application_organization_add_update.html")
	public String toMemberAdd() {
		return "/modules/application/application_organization_add_update";
	}

	// 知识库应用管理 -->机构用户管理-->查看详情
	@RequestMapping("application_organization_select.html")
	public String toListselect() {
		return "/modules/application/application_organization_select";
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理
	@RequestMapping("application_organization_user_list.html")
	public String toListselectAll() {
		return "/modules/application/application_organization_user_list";
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理
	@RequestMapping("application_organization_update_password.html")
	public String toUpdatePasswordManage() {
		return "/modules/application/application_organization_update_password";
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理--添加更新
	@RequestMapping("application_organization_user_add_update.html")
	public String toOrganizationselectAll() {
		return "/modules/application/application_organization_user_add_update";
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理--查看详情
	@RequestMapping("application_organization_user_select.html")
	public String toOrganizationUserselectAll() {
		return "/modules/application/application_organization_user_select";
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理--机构用户搜索
	@RequestMapping("application_organization_user_search.html")
	public String toOrganizationUserSearch() {
		return "/modules/application/application_organization_user_search";
	}

	// 知识库应用管理 -->知识库应用配置--新建互联登录配置
	@RequestMapping("application_setting_add.html")
	public String toConfiguration() {

		return "/modules/application/application_setting_add";
	}

	// 知识库应用管理 -->知识库应用配置--新建支付方式配置
	@RequestMapping("application_setting_payment_add.html")
	public String toPayment() {

		return "/modules/application/application_setting_payment_add";
	}

	// 统一交易--》充值管理
	@RequestMapping("application-organization-recharge.html")
	public String toRecharge() {

		return "/modules/pay/pay_organization_recharge";
	}

	// 充值管理--》充值历史
	@RequestMapping("pay-organization-recharge-history.html")
	public String toHistory() {

		return "/modules/pay/pay_organization_recharge_history";
	}

	// 统一交易--》订单管理
	@RequestMapping("application-organization-rechargeable.html")
	public String toRechargeable() {

		return "/modules/pay/pay_application_organization_rechargeable";
	}

	// 订单管理--》订单详情页
	@RequestMapping("pay-application-organization-rechargeable-detail.html")
	public ModelAndView toRechargeableDetail() {
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,status", 0);
		List<RepositoryProduct> repositoryProduct = publicService.getRepositoryProduct(queryParams, 1,
				publicService.getRepositoryProductCount(queryParams));
		ModelAndView view = new ModelAndView();
		view.addObject("classes", publicService.getClasses());
		view.addObject("project", payService.getProject());
		view.addObject("repositoryProduct", repositoryProduct);
		view.setViewName("/modules/pay/pay_application_organization_rechargeable_detail");
		return view;
	}

	// 统一身份认证管理--》批量导入用户
	@RequestMapping("application-user-add-batch.html")
	public String user_add_batch(HttpServletRequest request, HttpServletResponse response, Model model) {
		return "/modules/sso/application_user_add_batch";
	}

	/**
	 * 实现知识库应用管理-个人用户管理
	 */
	// 知识库应用管理 -->个人用户管理-->默认查询页面
	@RequestMapping("memberfindAll")
	@ResponseBody
	public void userfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Integer pageNumber = 15;
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		String type = request.getParameter("type");
		String memberId = request.getParameter("memberId");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		if (Integer.parseInt(type) == 0) {
			queryParams.put("=,type", type);
		} else if (Integer.parseInt(type) == 2) {
			queryParams.put("=,type", type);
			queryParams.put("=,memberId", memberId);
		}
		queryParams.put("^,create_time", "desc");
		Integer count = publicService.getMemberCount(queryParams);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		List<Member> list = publicService.getMember(queryParams, pageSize, pageNumber);
		for (int i = 0; i < list.size(); i++) {
			Member member = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", member.getId());
			mp.put("username", member.getUsername());
			mp.put("password", member.getPassword());
			mp.put("realname", member.getRealname());
			mp.put("nickname", member.getNickname());
			mp.put("type", member.getType());
			mp.put("createTime", member.getCreateTime());
			mp.put("createIpAddress", member.getCreateIpAddress());
			mp.put("avatarImg", member.getAvatarImg());
			mp.put("status", member.getStatus());
			mp.put("email", member.getEmail());
			mp.put("mobilephone", member.getMobilephone());
			mp.put("memberId", member.getMemberId());
			mp.put("balance", member.getBalance());
			mp.put("payment", member.getPayment());
			mp.put("telephone", member.getTelephone());
			mp.put("address", member.getAddress());
			if (member.getMemberId() != null && member.getMemberId() != 0) {
				Member department = publicService.findMember(member.getId());
				mp.put("departmentName", department.getRealname());
			} else {
				mp.put("departmentName", "");
			}
			String date = "null";
			if (member.getCreateTime() != null && !member.getCreateTime().equals("")) {
				date = member.getCreateTime();
			}
			mp.put("createTime", date);
			r.add(mp);
		}

		String result = formatToJson(r);
		StringBuffer sb = new StringBuffer();
		int listsize = r.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":" + (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"count\":" + count + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	// 知识库应用管理 -->个人用户管理 -->修改密码
	@RequestMapping("verifyMemberName")
	public void verifyMemberName(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String memberName = request.getParameter("memberName");
		String type = request.getParameter("type");
		LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("=,username", memberName);
		queryParams.put("=,type", type);
		r.put("count", publicService.getMemberCount(queryParams));
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}
	// 知识库应用管理 -->个人用户管理 -->添加
	@RequestMapping("userAddUpdate")
	@ResponseBody
	public void userAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {

		InetAddress addr = InetAddress.getLocalHost();
		String id = request.getParameter("id");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		String nickname = request.getParameter("nickname");
		String type = request.getParameter("type");
		String createTime = request.getParameter("createTime");
		if (null == createTime || "".equals(createTime)) {
			createTime = DateUtils.getDateTime().toString();
		}
		String createIpAddress = addr.getHostAddress();
		String avatarImg = request.getParameter("avatarImg");
		String status = request.getParameter("status");
		String email = request.getParameter("email");
		String mobilephone = request.getParameter("mobilephone");
		String education = request.getParameter("education");
		String profession = request.getParameter("profession");
		String researchField = request.getParameter("researchField");
		String workunit = request.getParameter("workunit");
		String title = request.getParameter("title");
		String certificateType = request.getParameter("certificateType");
		String certificateNumber = request.getParameter("certificateNumber");
		// System.out.println(createIpAddress);
		String memberId = request.getParameter("memberId");
		String balance = request.getParameter("balance");
		String payment = request.getParameter("payment");
		String age = request.getParameter("age");
		String gender = request.getParameter("gender");
		String keys = request.getParameter("keys");
		String address = request.getParameter("address");
		String telephone = request.getParameter("telephone");
		String validity = request.getParameter("validity");
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (avatarImg != null && !"".equals(avatarImg)) {
			avatarImg = avatarImg.replaceAll(uploadPath, "");
		}
		Member member = new Member();
		member.setUsername(username);
		member.setNickname(nickname);
		member.setRealname(realname);
		member.setCreateTime(createTime);
		member.setType(Integer.parseInt(type));
		member.setRealname(realname);
		member.setCreateIpAddress(createIpAddress);
		member.setAvatarImg(avatarImg);
		member.setStatus(Integer.parseInt(status));
		member.setEmail(email);
		member.setMobilephone(mobilephone);
		member.setEducation(education);
		member.setProfession(profession);
		member.setResearchField(researchField);
		member.setWorkunit(workunit);
		member.setTitle(title);
		member.setCertificateType(Integer.parseInt(certificateType));
		member.setCertificateNumber(certificateNumber);
		member.setAge(Integer.parseInt(age));
		member.setGender(Integer.parseInt(gender));
		member.setKeys(keys);
		member.setAddress(address);
		member.setTelephone(telephone);
		member.setValidity(validity);
		if (null != balance && !"".equals(balance)) {
			member.setBalance(new BigDecimal(balance));
		} else {
			member.setBalance(new BigDecimal("0.00"));
		}
		if (null != payment && !"".equals(payment)) {
			member.setPayment(new BigDecimal(payment));
		} else {
			member.setPayment(new BigDecimal("0.00"));
		}

		if (memberId != null) {
			member.setMemberId(Integer.parseInt(memberId));
		}
		int logTime = 0;

		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		// 新增
		if ("0".equals(id)) {
			if (!"".equals(password) && password != null) {
				member.setPassword(MD5.convert(password));
			}
			try {
				baseService.saveMember(member);
				member.setPassword(MD5.convert(password));
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【会员账号表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【会员账号表】成功！", 0);
			}

		} else {
			// 修改
			member.setPassword(password);
			try {
				member.setId(Integer.parseInt(id));
				baseService.editMember(member);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【会员账号表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【会员账号表】成功！", 0);
			}

		}

		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->个人用户管理 -->修改密码
	@RequestMapping("userUpdatePassword")
	public void toUserUpdatePassword(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String password = request.getParameter("newPassword");
		int logTime = 0;
		Member member = publicService.findMember(Integer.parseInt(id));
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		try {
			member.setPassword(MD5.convert(password));
			member.setId(Integer.parseInt(id));
			baseService.editMember(member);
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【会员账号表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【会员账号表】成功！", 0);
		}
		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 知识库应用管理 -->个人用户管理 -->生成秘钥
	@RequestMapping("createKeys")
	public void createKeys(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> keyMap = CreateSecrteKey.initKey();
		String keys = CreateSecrteKey.getPrivateKey(keyMap);
		LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
		r.put("keys", keys);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 删除单个用户
	@RequestMapping("memberdel")
	public void toMemberDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		List<String> r = new ArrayList<String>();
		String rString = "no";
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		try {
			Member member = publicService.findMember(id);
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,member_id", member.getId());
			int memberProjectCount = payService.getMemberProjectCount(queryParams);
			HashMap<String, Object> queryOrderParams = new LinkedHashMap<String, Object>();
			queryOrderParams.put("=,member_username", member.getUsername());
			int payOrderCount = payService.getPayOrderCount(queryOrderParams);
			if (memberProjectCount == 0 && payOrderCount == 0) {
				rString = "yes";
				baseService.deleteMember(member);
			}

		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】成功！", 0);
		}
		r.add(rString);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 删除选中用户
	@RequestMapping("memberDelAll")
	public void memberDelAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String[] valueIds =request.getParameterValues("valueIds");
		List<String> r = new ArrayList<String>();
		String rString = "no";
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		try {
			for (int i = 0; i < valueIds.length; i++) {
				Member member = publicService.findMember(Integer.parseInt(valueIds[i]));
				HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
				queryParams.put("=,member_id", member.getId());
				int memberProjectCount = payService.getMemberProjectCount(queryParams);
				HashMap<String, Object> queryOrderParams = new LinkedHashMap<String, Object>();
				queryOrderParams.put("=,member_username", member.getUsername());
				int payOrderCount = payService.getPayOrderCount(queryOrderParams);
				if (memberProjectCount == 0 && payOrderCount == 0) {
					rString = "yes";
					baseService.deleteMember(member);
				}
			}
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】成功！", 0);
		}
		r.add(rString);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 更新个人用户
	@RequestMapping("memberUpdate")
	public void toUserUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		Member member = publicService.findMember(id);
		String image = member.getAvatarImg();
		if (image != null && !"".equals(image)) {
			member.setAvatarImg(uploadPath + image);
		}
		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 查看详情
	@RequestMapping("memberSelect")
	public void toMemberSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		Member member = publicService.findMember(id);
		String image = member.getAvatarImg();
		if (image != null && !"".equals(image)) {
			member.setAvatarImg(uploadPath + image);
		}
		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	/*
	 * 实现知识库应用管理-机构用户管理
	 */
	// 知识库应用管理 -->机构用户管理-->默认查询页面
	@RequestMapping("listfindAll")
	@ResponseBody
	public void memberfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Integer pageNumber = 10;
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String username = request.getParameter("username");
		String realname = request.getParameter("realname");
		String type = request.getParameter("type");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (username != null && !"".equals(username)) {
			queryParams.put("%,username", username);
		}
		if (realname != null && !"".equals(realname)) {
			queryParams.put("%,realname", realname);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		Integer count = publicService.getMemberCount(queryParams);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		List<Member> list = publicService.getMember(queryParams, pageSize, pageNumber);
		for (int i = 0; i < list.size(); i++) {
			Member member = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", member.getId());
			mp.put("username", member.getUsername());
			mp.put("password", member.getPassword());
			mp.put("realname", member.getRealname());
			mp.put("nickname", member.getNickname());
			mp.put("type", member.getType());
			mp.put("createTime", member.getCreateTime());
			mp.put("createIpAddress", member.getCreateIpAddress());
			mp.put("avatarImg", member.getAvatarImg());
			mp.put("status", member.getStatus());
			mp.put("email", member.getEmail());
			mp.put("mobilephone", member.getMobilephone());
			mp.put("loginMode", member.getLoginMode());
			mp.put("memberId", member.getMemberId());
			mp.put("balance", member.getBalance());
			mp.put("payment", member.getPayment());
			mp.put("address", member.getAddress());
			mp.put("telephone", member.getTelephone());
			if (member.getMemberId() != null && member.getMemberId() != 0) {
				Member department = publicService.findMember(member.getId());
				mp.put("departmentName", department.getRealname());
			} else {
				mp.put("departmentName", "");
			}
			String date = "null";
			if (member.getCreateTime() != null && !member.getCreateTime().equals("")) {
				date = member.getCreateTime();
			}
			mp.put("createTime", date);
			r.add(mp);
		}

		String result = formatToJson(r);
		StringBuffer sb = new StringBuffer();
		int listsize = r.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":" + (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	@RequestMapping("payOrgAll")
	@ResponseBody
	public void payOrgAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Integer pageNumber = 10;
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String query = request.getParameter("queryParams");
		String text = request.getParameter("text");
		String type = request.getParameter("type");
		HashMap<String, Object> queryParamm = new HashMap<String, Object>();
		queryParamm.put("=,type", 2);
		Integer mcount = publicService.getMemberCount(queryParamm);
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + query, text);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		queryParams.put("^,create_time", "desc");
		Integer count = publicService.getMemberCount(queryParams);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		List<Member> list = publicService.getMember(queryParams, pageSize, pageNumber);
		for (int i = 0; i < list.size(); i++) {
			Member member = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", member.getId());
			mp.put("username", member.getUsername());
			mp.put("password", member.getPassword());
			mp.put("realname", member.getRealname());
			mp.put("nickname", member.getNickname());
			mp.put("type", member.getType());
			mp.put("createTime", member.getCreateTime());
			mp.put("createIpAddress", member.getCreateIpAddress());
			mp.put("avatarImg", member.getAvatarImg());
			mp.put("status", member.getStatus());
			mp.put("email", member.getEmail());
			mp.put("mobilephone", member.getMobilephone());
			mp.put("loginMode", member.getLoginMode());
			mp.put("memberId", member.getMemberId());
			mp.put("balance", member.getBalance());
			mp.put("payment", member.getPayment());
			mp.put("address", member.getAddress());
			mp.put("telephone", member.getTelephone());

			if (member.getMemberId() != null && member.getMemberId() != 0) {
				Member department = publicService.findMember(member.getId());
				mp.put("departmentName", department.getRealname());
			} else {
				mp.put("departmentName", "");
			}
			String date = "null";
			if (member.getCreateTime() != null && !member.getCreateTime().equals("")) {
				date = member.getCreateTime();
			}
			mp.put("createTime", date);
			r.add(mp);
		}

		String result = formatToJson(r);
		StringBuffer sb = new StringBuffer();
		int listsize = r.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":" + (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"count\":" + count + ",");
		sb.append("\"mcount\":" + mcount + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	// 查询项目
	@RequestMapping("queryJg")
	public void queryJg(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Member member = publicService.findMember(Integer.parseInt(id));
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if (1 == member.getType()) {
			queryParams.put("=,account_type", "Group");
		}
		if (0 == member.getType() || 2 == member.getType()) {
			queryParams.put("=,account_type", "Person");
		}
		List<Project> projectList = payService.getProject(queryParams, 1, payService.getProjectCount(queryParams));
		String resultString = formatToJson(projectList);
		super.pringWriterToPage(resultString, "application/json", response);
	}

	// 知识库应用管理 -->机构用户管理 -->添加
	@RequestMapping("listAddUpdate")
	@ResponseBody
	public void listAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {
		InetAddress addr = InetAddress.getLocalHost();
		String id = request.getParameter("id");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String realname = request.getParameter("realname");
		String nickname = request.getParameter("nickname");
		String type = request.getParameter("type");
		String createTime = DateUtils.getDateTime().toString();
		String createIpAddress = addr.getHostAddress();
		String avatarImg = request.getParameter("avatarImg");
		String status = request.getParameter("status");
		String email = request.getParameter("email");
		String balance = request.getParameter("balance");
		String payment = request.getParameter("payment");
		String mobilephone = request.getParameter("mobilephone");
		String keys = request.getParameter("keys");
		String ipSegment = request.getParameter("ipSegment");// 账号ip段（json存储，存储起止ip地址去掉点，缺少位补零）
		String loginMode = request.getParameter("loginMode");// 登录方式（0-用户名和密码
																// 1-ip自动登录）*
		String address = request.getParameter("address");
		String telephone = request.getParameter("telephone");
		String validity = request.getParameter("validity");
		String contact = request.getParameter("contact");
		String remarks = request.getParameter("remarks");
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (avatarImg != null && !"".equals(avatarImg)) {
			avatarImg = avatarImg.replaceAll(uploadPath, "");
		}
		Member member = new Member();
		member.setUsername(username);
		member.setPassword(password);
		member.setRealname(realname);
		member.setNickname(nickname);
		member.setCreateTime(createTime);
		member.setType(Integer.parseInt(type));
		member.setCreateIpAddress(createIpAddress);
		member.setAvatarImg(avatarImg);
		member.setStatus(Integer.parseInt(status));
		member.setEmail(email);
		member.setBalance(new BigDecimal(balance));
		member.setPayment(new BigDecimal(payment));
		member.setMobilephone(mobilephone);
		member.setLoginMode(Integer.parseInt(loginMode));
		member.setKeys(keys);
		member.setAddress(address);
		member.setTelephone(telephone);
		member.setValidity(validity);
		member.setContact(contact);
		member.setRemarks(remarks);
		int logTime = 0;

		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		// 新增
		Member aMember = null;
		if ("0".equals(id)) {
			try {
				if (!"".equals(password) && password != null) {
					member.setPassword(MD5.convert(password));
				}
				member.setPassword(MD5.convert(password));
				aMember = baseService.saveMember(member);
				if (ipSegment != null && !"".equals(ipSegment)) {
					String[] ips = ipSegment.split(";");
					for (int i = 0; i < ips.length; i++) {
						String[] ip = ips[i].split("-");
						IpLoginNumber ipLoginNumber = new IpLoginNumber();
						ipLoginNumber.setUserId(aMember.getId());
						if (ip != null && ip.length > 0) {
							ipLoginNumber.setStartIpAddressNumber(String.valueOf(IPConvertHelper.IPToNumber(ip[0])));
							ipLoginNumber.setEndIpAddressNmber(String.valueOf(IPConvertHelper.IPToNumber(ip[1])));
						}
						payService.saveIpLoginNumber(ipLoginNumber);
					}
				}
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【会员账号表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【会员账号表】成功！", 0);
			}

		} else {
			// 修改
			member.setPassword(password);
			try {
				member.setId(Integer.parseInt(id));
				baseService.editMember(member);
				if (ipSegment != null && !"".equals(ipSegment)) {
					String[] ips = ipSegment.split(";");
					HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
					queryParams.put("=,user_id", id);
					List<IpLoginNumber> IpLoginNumberList = payService.getIpLoginNumber(queryParams, 1,
							payService.getIpLoginNumberCount(queryParams));
					for (int i = 0; i < IpLoginNumberList.size(); i++) {
						IpLoginNumber ipLoginNumber = IpLoginNumberList.get(i);
						payService.deleteIpLoginNumber(ipLoginNumber);
					}
					for (int i = 0; i < ips.length; i++) {
						String[] ip = ips[i].split("-");
						if (ip != null && ip.length > 0) {
							IpLoginNumber ipLoginNumber = new IpLoginNumber();
							ipLoginNumber.setUserId(Integer.parseInt(id));
							ipLoginNumber.setStartIpAddressNumber(String.valueOf(IPConvertHelper.IPToNumber(ip[0])));
							ipLoginNumber.setEndIpAddressNmber(String.valueOf(IPConvertHelper.IPToNumber(ip[1])));
							payService.saveIpLoginNumber(ipLoginNumber);
						}
					}
				}
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【会员账号表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【会员账号表】成功！", 0);
			}

		}

		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 更新机构用户
	@RequestMapping("listUpdate")
	public void toListUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Member member = publicService.findMember(id);
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,user_id", member.getId());
		List<IpLoginNumber> ipLoginNumberList = payService.getIpLoginNumber(queryParams, 1,
				payService.getIpLoginNumberCount(queryParams));
		for (int i = 0; i < ipLoginNumberList.size(); i++) {
			IpLoginNumber ipLoginNumber = ipLoginNumberList.get(i);
			ipLoginNumber.setStartIpAddressNumber(
					IPConvertHelper.NumberToIP(Long.parseLong(ipLoginNumber.getStartIpAddressNumber())));
			ipLoginNumber.setEndIpAddressNmber(
					IPConvertHelper.NumberToIP(Long.parseLong(ipLoginNumber.getEndIpAddressNmber())));
		}
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (member.getAvatarImg() != null && !"".equals(member.getAvatarImg())) {
			member.setAvatarImg(uploadPath + member.getAvatarImg());
		}
		LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
		r.put("member", member);
		r.put("ipLoginNumberList", ipLoginNumberList);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 删除机构用户
	@RequestMapping("listdel")
	public void toListDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		int logTime = 0;

		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		List<String> r = new ArrayList<String>();
		String rString = "no";
		String rzString = "yes";
		try {
			Member member = publicService.findMember(id);
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("=,member_id", member.getId());
			List<Member> memberz = publicService.getMember(queryParams, 1, Integer.MAX_VALUE);
			for (Member memz : memberz) {
				HashMap<String, Object> queryParamzs = new LinkedHashMap<String, Object>();
				queryParamzs.put("=,member_id", memz.getId());
				int memzProjectCount = payService.getMemberProjectCount(queryParamzs);
				HashMap<String, Object> queryOrderParamzs = new LinkedHashMap<String, Object>();
				queryOrderParamzs.put("=,member_username", memz.getUsername());
				int payOrderzCount = payService.getPayOrderCount(queryOrderParamzs);
				if (memzProjectCount == 0 && payOrderzCount == 0) {
					baseService.deleteMember(memz);
				} else {
					rzString = "no";
				}
			}
			if (rzString == "yes") {
				int memberProjectCount = payService.getMemberProjectCount(queryParams);
				HashMap<String, Object> queryOrderParams = new LinkedHashMap<String, Object>();
				queryOrderParams.put("=,member_username", member.getUsername());
				int payOrderCount = payService.getPayOrderCount(queryOrderParams);
				if (memberProjectCount == 0 && payOrderCount == 0) {
					rString = "yes";
					baseService.deleteMember(member);
				}
			}
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【会员账号表】成功！", 0);
		}
		r.add(rString);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 查看详情
	@RequestMapping("listSelect")
	public void toListSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Member member = publicService.findMember(id);
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,user_id", member.getId());
		List<IpLoginNumber> ipLoginNumberList = payService.getIpLoginNumber(queryParams, 1,
				payService.getIpLoginNumberCount(queryParams));
		for (int i = 0; i < ipLoginNumberList.size(); i++) {
			IpLoginNumber ipLoginNumber = ipLoginNumberList.get(i);
			ipLoginNumber.setStartIpAddressNumber(
					IPConvertHelper.NumberToIP(Long.parseLong(ipLoginNumber.getStartIpAddressNumber())));
			ipLoginNumber.setEndIpAddressNmber(
					IPConvertHelper.NumberToIP(Long.parseLong(ipLoginNumber.getEndIpAddressNmber())));
		}
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (member.getAvatarImg() != null && !"".equals(member.getAvatarImg())) {
			member.setAvatarImg(uploadPath + member.getAvatarImg());
		}
		LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
		r.put("member", member);
		r.put("ipLoginNumberList", ipLoginNumberList);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户搜索默认查询页面
	@RequestMapping("organizationUserSeach")
	@ResponseBody
	public void organizationfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Integer pageNumber = 15;
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		String type = request.getParameter("type");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("=,type", type);
		Integer count = publicService.getMemberCount(queryParams);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		List<Member> list = publicService.getMember(queryParams, pageSize, pageNumber);
		for (int i = 0; i < list.size(); i++) {
			Member member = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", member.getId());
			mp.put("username", member.getUsername());
			mp.put("password", member.getPassword());
			mp.put("realname", member.getRealname());
			mp.put("nickname", member.getNickname());
			mp.put("type", member.getType());
			mp.put("createTime", member.getCreateTime());
			mp.put("createIpAddress", member.getCreateIpAddress());
			mp.put("avatarImg", member.getAvatarImg());
			mp.put("status", member.getStatus());
			mp.put("email", member.getEmail());
			mp.put("mobilephone", member.getMobilephone());
			mp.put("loginMode", member.getLoginMode());
			mp.put("memberId", member.getMemberId());
			mp.put("address", member.getAddress());
			mp.put("telephone", member.getTelephone());

			if (member.getType() == 2) {
				Member department = publicService.findMember(member.getMemberId());
				mp.put("departmentName", department.getRealname());
			}

			String date = "null";
			if (member.getCreateTime() != null && !member.getCreateTime().equals("")) {
				date = member.getCreateTime();
			}
			mp.put("createTime", date);
			r.add(mp);
		}

		String result = formatToJson(r);
		StringBuffer sb = new StringBuffer();
		int listsize = r.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":" + (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理--更新机构用户
	@RequestMapping("organizationUserUpdate")
	public void toOrganizationUserUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Member member = publicService.findMember(id);
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (member.getAvatarImg() != null && !"".equals(member.getAvatarImg())) {
			member.setAvatarImg(uploadPath + member.getAvatarImg());
		}
		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->机构用户管理-->机构下用户管理 查看详情
	@RequestMapping("OrganizationUserSelect")
	public void toOrganizationUserSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Member member = publicService.findMember(id);
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (member.getAvatarImg() != null && !"".equals(member.getAvatarImg())) {
			member.setAvatarImg(uploadPath + member.getAvatarImg());
		}
		String result = formatToJson(member);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	/*
	 * 实现知识库应用配置
	 */
	// 知识库应用管理 -->知识库支付配置-->默认查询页面
	@RequestMapping("listfindPayment")
	@ResponseBody
	public void PaymentfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		List<Payment> payments = publicService.getPayment();

		String result = formatToJson(payments);
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->支付配置管理 -->添加
	@RequestMapping("paymentAdd")
	@ResponseBody
	public void paymentAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String appid = request.getParameter("appid");
		String appsecret = request.getParameter("appsecret");
		String type = request.getParameter("type");
		Payment payment = new Payment();
		payment.setAppid(appid);
		payment.setAppsecret(appsecret);
		payment.setType(Integer.parseInt(type));

		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		// 新增
		if ("0".equals(id)) {

			try {
				baseService.savePayment(payment);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【支付方式表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【支付方式表】成功！", 0);
			}

		} else {
			// 修改

			try {
				payment.setId(Integer.parseInt(id));
				baseService.editPayment(payment);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【支付方式表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【支付方式表】成功！", 0);
			}

			String result = formatToJson(payment);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
	}

	// 知识库应用管理 -->支付配置管理 -更新
	@RequestMapping("paymentUpdate")
	public void toPaymentUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Payment payment = new Payment();
		payment = publicService.findPayment(id);
		String result = formatToJson(payment);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->支付配置管理 -删除
	@RequestMapping("paymentdel")
	public void toPaymentDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));

		Payment payment = new Payment();
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		try {
			payment = publicService.findPayment(id);
			baseService.deletePayment(payment);
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【支付方式表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【支付方式表】成功！", 0);
		}

		String result = formatToJson(payment);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库应用配置管理-->默认查询页面
	@RequestMapping("listfindConfiguration")
	@ResponseBody
	public void openLoginfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {

		List<OpenLogin> openLogins = publicService.getOpenLogin();

		String result = formatToJson(openLogins);
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库应用配置管理 -->添加
	@RequestMapping("settingAdd")
	@ResponseBody
	public void settingAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String appid = request.getParameter("appid");
		String appsecret = request.getParameter("appsecret");
		String type = request.getParameter("type");
		OpenLogin openLogin = new OpenLogin();
		openLogin.setAppid(appid);
		openLogin.setAppsecret(appsecret);
		openLogin.setType(Integer.parseInt(type));
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		// 新增
		if ("0".equals(id)) {

			try {
				baseService.saveOpenLogin(openLogin);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【第三方互联登录配置表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【第三方互联登录配置表】成功！",
						0);
			}

		} else {
			// 修改

			try {
				openLogin.setId(Integer.parseInt(id));
				baseService.editOpenLogin(openLogin);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【第三方互联登录配置表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【第三方互联登录配置表】成功！",
						0);
			}

			String result = formatToJson(openLogin);
			super.pringWriterToPage(result.toString(), "application/json", response);
		}
	}

	// 知识库应用管理 -->知识库应用配置管理 -更新
	@RequestMapping("openLoginUpdate")
	public void toOpenLoginUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		OpenLogin openLogin = new OpenLogin();
		openLogin = publicService.findOpenLogin(id);
		String result = formatToJson(openLogin);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库应用配置管理 -删除
	@RequestMapping("openLogindel")
	public void toOpenLoginDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		OpenLogin openLogin = new OpenLogin();
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		try {
			openLogin = publicService.findOpenLogin(id);
			baseService.deleteOpenLogin(openLogin);
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null,
					"【" + user.getNickname() + "】【删除】【第三方互联登录配置表】 失败！请检查数据是否正确！", 1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【第三方互联登录配置表】成功！", 0);
		}

		String result = formatToJson(openLogin);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	/*
	 * 实现知识库产品管理
	 */
	// 知识库应用管理 -->知识库产品管理 -->默认查询页面
	@RequestMapping("listfindRepositoryProduct")
	@ResponseBody
	public void repositoryProductfindAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%,name", text);
		}
		List<RepositoryProduct> repositoryProducts = publicService.getRepositoryProduct(queryParams, 1,
				publicService.getRepositoryProductCount(queryParams));
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		for (RepositoryProduct rp : repositoryProducts) {
			String classesids = rp.getClassesIds();
			String classesName = "";
			if (classesids != null && !"".equals(classesids)) {
				classesids = classesids.substring(0, classesids.length() - 1);
				String classes[] = classesids.split(",");
				for (int i = 0; i < classes.length; i++) {
					Classes c = publicService.findClasses(Integer.parseInt(classes[i]));
					if (c != null) {
						classesName += c.getNameZh() + ",";
					}
				}
			}
			rp.setClassesIds(classesName);
			if (rp.getCoverImg() != null && !"".equals(rp.getCoverImg())) {
				rp.setCoverImg(uploadPath + rp.getCoverImg());
			}
		}
		String result = formatToJson(repositoryProducts);
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库产品管理 -->默认Classes查询
	@RequestMapping("queryclasses")
	@ResponseBody
	public void queryclasses(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Classes> classes = publicService.getClasses();
		String result = formatToJson(classes);
		// System.out.println(result);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库产品管理 -->添加
	@RequestMapping("Addproduct")
	@ResponseBody
	public void AddProduct(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String description = request.getParameter("description");
		String price = request.getParameter("price");
		String units = request.getParameter("units");
		String webUrl = request.getParameter("webUrl");
		String[] classesIds = request.getParameterValues("classesIds");
		String searchExpression = request.getParameter("searchExpression");
		String searchExpressionAdditional = request.getParameter("searchExpressionAdditional");
		String isSynchronous = request.getParameter("isSynchronous");
		String solrCoreUrl = request.getParameter("solrCoreUrl");
		String coverImg = request.getParameter("coverImg");
		String preferential = request.getParameter("preferential");
		String chargeType = request.getParameter("chargeType");
		String preferentialDateStart = request.getParameter("preferentialDateStart");
		String preferentialDateEnd = request.getParameter("preferentialDateEnd");
		String categorySid = request.getParameter("categorySid");
		String pid = request.getParameter("pid");
		String classesId = "";
		if (classesIds != null && classesIds.length > 0) {
			for (int i = 0; i < classesIds.length; i++) {
				classesId += classesIds[i] + ",";
			}
		}
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (coverImg != null && !"".equals(coverImg)) {
			coverImg = coverImg.replaceAll(uploadPath, "");
		}
		RepositoryProduct repository = null;

		// 新增
		if ("0".equals(id)) {
			repository = new RepositoryProduct();
		} else {
			repository = publicService.findRepositoryProduct(Integer.parseInt(id));
		}
		repository.setPid(Integer.valueOf(pid));
		repository.setName(name);
		repository.setDescription(description);
		if (price != null && !"".equals(price)) {
			repository.setPrice(new BigDecimal(price));
		}
		// repository.setPreferential(new BigDecimal(preferential));
		repository.setStatus(0);
		repository.setUnits(units);
		repository.setWebUrl(webUrl);
		repository.setClassesIds(classesId);
		repository.setSearchExpression(searchExpression);
		repository.setSearchExpressionAdditional(searchExpressionAdditional);
		repository.setIsSynchronous(Integer.parseInt(isSynchronous));
		repository.setSolrCoreUrl(solrCoreUrl);
		repository.setCoverImg(coverImg);
		repository.setCategorySid(categorySid);
		;
		if (preferential != null && !"".equals(preferential)) {
			repository.setPreferentialPrice(new BigDecimal(preferential));
		}
		repository.setPreferentialDateStart(preferentialDateStart);
		repository.setPreferentialDateEnd(preferentialDateEnd);
		if (chargeType != null && !"".equals(chargeType)) {
			repository.setChargeType(Integer.parseInt(chargeType));
		}
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		// 新增
		if ("0".equals(id)) {
			String createTime = DateUtils.getDateTime();
			repository.setCreateTime(createTime);
			try {
				baseService.saveRepositoryProduct(repository);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【知识库产品表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【知识库产品表】成功！", 0);
			}

		} else {
			// 修改
			try {
				// repository.setId(Integer.parseInt(id));
				baseService.editRepositoryProduct(repository);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【知识库产品表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【知识库产品表】成功！", 0);
			}

		}

		String result = formatToJson(repository);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	@RequestMapping("repositoryProductsubmit")
	public void toRepositoryProductsubmit(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		Integer submitid = Integer.parseInt(request.getParameter("submitid"));
		RepositoryProduct repository = new RepositoryProduct();
		repository = publicService.findRepositoryProduct(id);
		if (submitid == 0) {
			repository.setStatus(1);
		} else if (submitid == 1) {
			repository.setStatus(0);
		} else if (submitid == 2) {
			repository.setStatus(-1);
		}
		baseService.editRepositoryProduct(repository);
		String result = formatToJson(repository);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库产品管理 -->更新
	@RequestMapping("repositoryProductUpdate")
	public void toRepositoryProductUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		RepositoryProduct repository = publicService.findRepositoryProduct(id);
		// 获取服务器地址
		String uploadPath = XxlConfClient.get("dal.file.server", "") + "/";
		if (repository.getCoverImg() != null && !"".equals(repository.getCoverImg())) {
			repository.setCoverImg(uploadPath + repository.getCoverImg());
		}

		String categorySid = repository.getCategorySid();
		if (categorySid != null && !"".equals(categorySid)) {
			String categoryName = "";
			HashMap<String, Object> querydictParams = new HashMap<String, Object>();
			querydictParams.put("=,name_en", "product_category");
			List<Dict> dictList = publicService.getDict(querydictParams, 1, 1);
			if (null != dictList && dictList.size() > 0) {
				Dict dict = dictList.get(0);
				String values[] = categorySid.split(";");
				HashMap<String, Object> queryParams = null;
				for (int i = 0; i < values.length; i++) {
					queryParams = new HashMap<String, Object>();
					queryParams.put("=,dict_id", dict.getId());
					queryParams.put("=,value", values[i]);
					List<DictItem> dictItemList = publicService.getDictItem(queryParams, 1, 1);
					if (null != dictItemList && dictItemList.size() > 0) {
						DictItem dictItem = dictItemList.get(0);
						categoryName += dictItem.getNameZh() + ";";
					}
				}
				repository.setCategorySid(repository.getCategorySid() + "∷" + categoryName);
			}
		}

		String result = formatToJson(repository);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->知识库产品管理 -->删除
	@RequestMapping("repositoryProductdel")
	public void toRepositoryProductDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		List<Integer> r = new ArrayList<Integer>();
		int count = 0;
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		try {
			RepositoryProduct repository = publicService.findRepositoryProduct(id);
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("%,productDetail", repository.getId() + ",");
			count = payService.getProjectCount(queryParams);
			if (count == 0) {
				baseService.deleteRepositoryProduct(repository);
			}
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【知识库产品表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【知识库产品表】成功！", 0);
		}

		r.add(count);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 产品库添加字典
	@RequestMapping("showCategorySid")
	public void showCategorySid(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String dictItemEn = request.getParameter("dictItemEn");
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		HashMap<String, Object> querydictParams = new HashMap<String, Object>();
		querydictParams.put("=,name_en", dictItemEn);
		List<Dict> dictList = publicService.getDict(querydictParams, 1, 1);
		if (null != dictList && dictList.size() > 0) {
			Dict dict = dictList.get(0);
			HashMap<String, Object> queryParams = new HashMap<String, Object>();
			queryParams.put("=,dict_id", dict.getId());
			List<DictItem> dictItemList = publicService.getDictItem(queryParams, Integer.parseInt(page), 10);
			int count = publicService.getDictItemCount(queryParams);
			mp.put("data", dictItemList);
			mp.put("count", count);
			mp.put("page", (int) Math.ceil(Double.valueOf(count) / 10));
		}
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);

	}

	// 充值管理---》查询
	@RequestMapping("queryRecharge")
	public void queryRecharge(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		String username = request.getParameter("username");
		username = username.replaceAll(" ", "");
		String nickname = request.getParameter("nickname");
		nickname = nickname.replaceAll(" ", "");
		String realname = request.getParameter("realname");
		realname = realname.replaceAll(" ", "");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if ("0".equals(type)) {
			if (username != null && !"".equals(username)) {
				queryParams.put("=,username", username);
			}
			if (nickname != null && !"".equals(nickname)) {
				queryParams.put("=,nickname", nickname);
			}
			if (realname != null && !"".equals(realname)) {
				queryParams.put("=,realname", realname);
			}
		} else {
			if (username != null && !"".equals(username)) {
				queryParams.put("%,username", username);
			}
			if (nickname != null && !"".equals(nickname)) {
				queryParams.put("%,nickname", nickname);
			}
			if (realname != null && !"".equals(realname)) {
				queryParams.put("%,realname", realname);
			}
		}
		queryParams.put("!,type", 1);
		queryParams.put("^,create_time", "desc");
		List<Member> memberList = null;
		if (queryParams.size() > 1) {
			memberList = publicService.getMember(queryParams, 1, publicService.getMemberCount(queryParams).intValue());
		}
		String result = formatToJson(memberList);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 充值管理---》充值
	@RequestMapping("saveMoney")
	public void saveMoney(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String money = request.getParameter("money");
		String id = request.getParameter("id");
		int userid = Integer.parseInt(request.getSession().getAttribute("userid").toString());
		String createTime = DateUtils.getDateTime();
		String r = "yes";
		Member member = publicService.findMember(Integer.parseInt(id));
		PayRecharge payRecharge = new PayRecharge();
		payRecharge.setCreateUserId(userid);
		payRecharge.setMemberUsername(member.getUsername());
		payRecharge.setPayMoney(new BigDecimal(money));
		payRecharge.setPayTime(createTime);
		payRecharge.setStatus(0);
		BigDecimal bigDecimal = member.getBalance();
		String[] moneys = money.split("-");
		if (moneys.length > 1) {
			if (bigDecimal != null && !"".equals(bigDecimal)) {
				member.setBalance(bigDecimal.subtract(new BigDecimal(moneys[1])));
			} else {
				r = "error";
			}
		} else {
			if (bigDecimal != null && !"".equals(bigDecimal)) {
				member.setBalance(bigDecimal.add(new BigDecimal(money)));
			} else {
				member.setBalance(new BigDecimal(money));
			}
		}
		try {
			payService.savePayRecharge(payRecharge);
			baseService.editMember(member);
		} catch (Exception e) {
			e.printStackTrace();
			r = "no";
		}
		List<String> list = new ArrayList<String>();
		list.add(r);
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 充值管理---》充值历史
	@RequestMapping("queryhistory")
	public void queryhistory(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String id = request.getParameter("id");
		Member member = publicService.findMember(Integer.parseInt(id));
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,member_username", member.getUsername());
		queryParams.put("^,pay_time", "desc");
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		List<PayRecharge> payRechargeList = payService.getPayRecharge(queryParams, Integer.parseInt(page), 10);
		int count = payService.getPayRechargeCount(queryParams).intValue();
		mp.put("payRecharge", payRechargeList);
		mp.put("user", publicService.getUser());
		mp.put("count", (int) Math.ceil(Double.valueOf(count) / 10));
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 订单查询
	@RequestMapping("queryrechargeable")
	public void queryrechargeable(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String orderNumber = request.getParameter("orderNumber");
		String memberUsername = request.getParameter("memberUsername");
		String status = request.getParameter("status");
		String payWay = request.getParameter("payWay");
		String memberType = request.getParameter("memberType");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if (orderNumber != null && !"".equals(orderNumber)) {
			queryParams.put("%,order_number", orderNumber);
		}
		if (memberUsername != null && !"".equals(memberUsername)) {
			queryParams.put("%,member_username", memberUsername);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		if (payWay != null && !"".equals(payWay)) {
			queryParams.put("=,pay_way", payWay);
		}
		if (memberType != null && !"".equals(memberType)) {
			queryParams.put("=,member_type", memberType);
		}
		if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)) {
			queryParams.put(">=,create_time", startTime);
			queryParams.put("<,create_time", endTime);
		}
		queryParams.put("^,create_time", "desc");
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		int count = payService.getPayOrderCount(queryParams).intValue();
		List<PayOrder> payOrderList = payService.getPayOrder(queryParams, Integer.parseInt(page), 15);
		HashMap<String, Object> queryMemberParams = null;
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> data = null;
		for (int i = 0; i < payOrderList.size(); i++) {
			PayOrder payOrder = payOrderList.get(i);
			queryMemberParams = new LinkedHashMap<String, Object>();
			data = new LinkedHashMap<String, Object>();
			data.put("id", payOrder.getId());
			data.put("memberUsername", payOrder.getMemberUsername());
			data.put("memberType", payOrder.getMemberType());
			data.put("payWay", payOrder.getPayWay());
			data.put("status", payOrder.getStatus());
			data.put("payPreferential", payOrder.getPayPreferential());
			data.put("payMoney", payOrder.getPayMoney());
			data.put("createTime", payOrder.getCreateTime());
			data.put("createIpAddress", payOrder.getCreateIpAddress());
			data.put("orderNumber", payOrder.getOrderNumber());
			data.put("totalMoney", payOrder.getTotalMoney());
			data.put("createIpAddress", payOrder.getCreateIpAddress());
			queryMemberParams.put("=,username", payOrder.getMemberUsername());
			List<Member> MemberList = publicService.getMember(queryMemberParams, 1, 1);
			if (null != MemberList && MemberList.size() > 0) {
				data.put("mobilephone", MemberList.get(0).getMobilephone());
			} else {
				data.put("mobilephone", "");
			}
			r.add(data);
		}

		mp.put("payOrderList", r);
		mp.put("count", (int) Math.ceil(Double.valueOf(count) / 15));
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 订单详情
	@RequestMapping("rechargeableDetail")
	public void rechargeableDetail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String id = request.getParameter("id");
		String classes = request.getParameter("classes");
		String title = request.getParameter("title");
		String resourcesId = request.getParameter("resourcesId");
		String repositoryProductId = request.getParameter("repositoryProduct");
		String aProjectId = request.getParameter("project");

		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		HashMap<String, Object> classesQueryParams = null;
		queryParams.put("=,pay_order_id", id);
		if (classes != null && !"".equals(classes)) {
			queryParams.put("=,resources_type", classes);
		}
		if (title != null && !"".equals(title)) {
			queryParams.put("%,resources_title", title);
		}
		if (resourcesId != null && !"".equals(resourcesId)) {
			queryParams.put("%,resources_id", resourcesId);
		}
		if (repositoryProductId != null && !"".equals(repositoryProductId)) {
			queryParams.put("=,repository_product_id", repositoryProductId);
		}
		if (aProjectId != null && !"".equals(aProjectId)) {
			queryParams.put("=,project_id", aProjectId);
		}
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, Object> detailList = null;
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		List<PayOrderDetail> payOrderDetailList = payService.getPayOrderDetail(queryParams, Integer.parseInt(page), 7);
		int count = payService.getPayOrderDetailCount(queryParams).intValue();
		for (int i = 0; i < payOrderDetailList.size(); i++) {
			PayOrderDetail payOrderDetail = payOrderDetailList.get(i);
			detailList = new LinkedHashMap<String, Object>();
			classesQueryParams = new LinkedHashMap<String, Object>();
			classesQueryParams.put("=,name_en", payOrderDetail.getResourcesType());
			List<Classes> cs = publicService.getClasses(classesQueryParams, 1, 1);
			if (cs != null && cs.size() > 0) {
				detailList.put("resourcesType", cs.get(0).getNameZh());
			} else {
				detailList.put("resourcesType", payOrderDetail.getResourcesType());
			}
			detailList.put("resourcesId", payOrderDetail.getResourcesId());
			detailList.put("resourcesTitle", payOrderDetail.getResourcesTitle());
			detailList.put("resourcesPrice", payOrderDetail.getResourcesPrice());
			detailList.put("resourcesPreferential", payOrderDetail.getResourcesPreferential());
			detailList.put("resourcesCount", payOrderDetail.getResourcesCount());
			Integer projectId = payOrderDetail.getProjectId();
			// 项目
			if (projectId != null && !"".equals(projectId) && projectId != 0) {
				Project project = payService.findProject(projectId);
				detailList.put("projectName", project.getNameZh());
			} else {
				detailList.put("projectName", "");
			}
			if (payOrderDetail.getRepositoryProductId() != null
					&& !"".equals(payOrderDetail.getRepositoryProductId())) {
				RepositoryProduct repositoryProduct = publicService
						.findRepositoryProduct(payOrderDetail.getRepositoryProductId());
				if (repositoryProduct != null && !"".equals(repositoryProduct)) {
					detailList.put("repositoryProductName", repositoryProduct.getName());
				} else {
					detailList.put("repositoryProductName", "");
				}
			} else {
				detailList.put("repositoryProductName", "");
			}
			r.add(detailList);
		}
		mp.put("payOrderDetailList", r);
		mp.put("count", (int) Math.ceil(Double.valueOf(count) / 7));
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 统一身份认证管理--》excel批量导入
	@RequestMapping("applicationUserAddBatch")
	public void applicationUserAddBatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String filePath = request.getParameter("filePath");
		String type = request.getParameter("type");
		String sheetName = request.getParameter("sheetName");
		String memberId = request.getParameter("memberId");
		int applicationUserAddBatch = dataHandlingService.applicationUserAddBatch(filePath, sheetName, type, memberId);
		String result = formatToJson("[{\"result\":\"success\",\"msg\":\"" + applicationUserAddBatch + "\"}]");
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// --统一身份认证管理--》模板下载
	@RequestMapping("userAddBatchModelDownload")
	public void userAddBatchModelDownload(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String filename = "modelAndInstructions.zip";
		String path = XxlConfClient.get("dal.file.path", "") + "/model";
		if (filename != null) {
			path = path + "/" + filename;
			// 设置响应头，控制浏览器下载该文件
			filename = new String(filename.getBytes("UTF-8"), "ISO-8859-1");
			response.setHeader("content-disposition", "attachment;filename=" + filename);
			response.setContentType("application/octet-stream");
			response.setContentType("application/OCTET-STREAM;charset=UTF-8");
			// 读取要下载的文件，保存到文件输入流
			FileInputStream in = new FileInputStream(path);
			// 创建输出流
			OutputStream out = response.getOutputStream();
			// 创建缓冲区
			byte buffer[] = new byte[1024];
			int len = 0;
			// 循环将输入流中的内容读取到缓冲区当中
			while ((len = in.read(buffer)) > 0) {
				// 输出缓冲区的内容到浏览器，实现文件下载
				out.write(buffer, 0, len);
			}
			// 关闭文件输入流
			in.close();
			// 关闭输出流
			out.close();
			// return aApiModel;
		}
	}

	// 导出订单
	@RequestMapping("exportIndentsubmit")
	public void exportIndentsubmit(HttpServletRequest request, HttpServletResponse response) {
		ServletContext sc = request.getSession().getServletContext();
		String dir = sc.getRealPath("/XMLFile/");
		File dirFile = new File(dir);
		if (!dirFile.exists()) {
			dirFile.mkdirs();
		}
		// DBUtils.writeExcel(path, list, flag);

		String[] columnNames = { "用户名", "用户类型", "支付方式", "电话", "订单号", "资源支付金额", "资源优惠/折扣总金额", "状态", "订单日期" };
		int[] columnWidths = { 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 };
		List<List<String>> data = new ArrayList<List<String>>();
		List<String> r = null;
		HashMap<String, Object> queryMemberParams = null;
		List<PayOrder> payOrderList = payService.getPayOrder();
		if (null != payOrderList && payOrderList.size() > 0) {
			for (int i = 0; i < payOrderList.size(); i++) {
				PayOrder payOrder = payOrderList.get(i);
				r = new ArrayList<String>();
				queryMemberParams = new LinkedHashMap<String, Object>();
				String start = "";
				if (0 == payOrder.getStatus()) {
					start = "支付成功";
				} else {
					start = "待支付";
				}
				String memberType = "";
				if (0 == payOrder.getMemberType()) {
					memberType = "个人";
				} else {
					memberType = "机构";
				}

				queryMemberParams.put("=,username", payOrder.getMemberUsername());
				List<Member> MemberList = publicService.getMember(queryMemberParams, 1, 1);

				r.add(payOrder.getMemberUsername());
				r.add(memberType);
				r.add(payOrder.getPayWay());
				if (null != MemberList && MemberList.size() > 0) {
					r.add(MemberList.get(0).getMobilephone());
				} else {
					r.add("");
				}
				r.add(payOrder.getOrderNumber());
				r.add(payOrder.getPayMoney().toString());
				r.add(payOrder.getPayPreferential().toString());
				r.add(start);
				r.add(payOrder.getCreateTime());
				data.add(r);
			}
		}

		String random = System.nanoTime() + ".xls";
		File downFile = new File(dirFile, random);
		ExcelUtil.dataToExcel(data, downFile.getPath(), columnNames, columnWidths);
		try {
			FileDownloadUtil.download(downFile, "订单.xls", request, response);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 导出订单详情
	@RequestMapping("exportIndentsubmitDetails")
	public void exportIndentsubmitDetails(HttpServletRequest request, HttpServletResponse response) {
		ServletContext sc = request.getSession().getServletContext();
		String dir = sc.getRealPath("/XMLFile/");
		File dirFile = new File(dir);
		if (!dirFile.exists()) {
			dirFile.mkdirs();
		}
		// DBUtils.writeExcel(path, list, flag);

		String[] columnNames = { "订单号", "资源类型", "资源ID", "资源标题", "资源单价", "资源优惠信息", "资源数量", "所属产品", "所属项目" };
		int[] columnWidths = { 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000 };
		List<List<String>> data = new ArrayList<List<String>>();
		List<String> r = null;
		HashMap<String, Object> queryMemberParams = null;

		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, Object> detailList = null;
		HashMap<String, Object> classesQueryParams = null;
		List<HashMap<String, Object>> detailr = new ArrayList<HashMap<String, Object>>();
		List<PayOrderDetail> payOrderDetailList = payService.getPayOrderDetail();
		for (int i = 0; i < payOrderDetailList.size(); i++) {
			PayOrderDetail payOrderDetail = payOrderDetailList.get(i);
			detailList = new LinkedHashMap<String, Object>();
			classesQueryParams = new LinkedHashMap<String, Object>();
			classesQueryParams.put("=,name_en", payOrderDetail.getResourcesType());
			List<Classes> cs = publicService.getClasses(classesQueryParams, 1, 1);
			if (cs != null && cs.size() > 0) {
				detailList.put("resourcesType", cs.get(0).getNameZh());
			} else {
				detailList.put("resourcesType", payOrderDetail.getResourcesType());
			}
			detailList.put("resourcesId", payOrderDetail.getResourcesId());
			detailList.put("resourcesTitle", payOrderDetail.getResourcesTitle());
			detailList.put("resourcesPrice", payOrderDetail.getResourcesPrice());
			detailList.put("orderDetalNumber", payOrderDetail.getOrderDetalNumber());
			detailList.put("resourcesPreferential", payOrderDetail.getResourcesPreferential());
			detailList.put("resourcesCount", payOrderDetail.getResourcesCount());
			Integer projectId = payOrderDetail.getProjectId();
			// 项目
			if (null != projectId && !"".equals(projectId) && projectId != 0) {
				Project project = payService.findProject(projectId);
				if (null != project) {
					detailList.put("projectName", project.getNameZh());
				} else {
					detailList.put("projectName", "");
				}
			} else {
				detailList.put("projectName", "");
			}
			if (payOrderDetail.getRepositoryProductId() != null
					&& !"".equals(payOrderDetail.getRepositoryProductId())) {
				RepositoryProduct repositoryProduct = publicService
						.findRepositoryProduct(payOrderDetail.getRepositoryProductId());
				if (repositoryProduct != null && !"".equals(repositoryProduct)) {
					detailList.put("repositoryProductName", repositoryProduct.getName());
				} else {
					detailList.put("repositoryProductName", "");
				}
			} else {
				detailList.put("repositoryProductName", "");
			}
			detailr.add(detailList);
		}

		if (null != detailr && detailr.size() > 0) {
			for (int i = 0; i < detailr.size(); i++) {
				HashMap<String, Object> keyValue = detailr.get(i);
				r = new ArrayList<String>();
				r.add(keyValue.get("orderDetalNumber").toString());
				r.add(keyValue.get("resourcesType").toString());
				r.add(keyValue.get("resourcesId").toString());
				r.add(keyValue.get("resourcesTitle").toString());
				r.add(keyValue.get("resourcesPrice").toString());
				r.add(keyValue.get("resourcesPreferential").toString());
				r.add(keyValue.get("resourcesCount").toString());
				r.add(keyValue.get("repositoryProductName").toString());
				r.add(keyValue.get("projectName").toString());
				data.add(r);
			}
		}

		String random = System.nanoTime() + ".xls";
		File downFile = new File(dirFile, random);
		ExcelUtil.dataToExcel(data, downFile.getPath(), columnNames, columnWidths);
		try {
			FileDownloadUtil.download(downFile, "订单详情.xls", request, response);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 查询专题列表
	@RequestMapping("applicationQuerySpecialManage")
	public void toApplicationQuerySpecialManage(HttpServletResponse response) throws Exception {

		List<RepositoryProduct> list1 = publicService.getRepositoryProduct();
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list1.size(); i++) {
			RepositoryProduct repositoryProduct = list1.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", repositoryProduct.getId());
			mp.put("name", repositoryProduct.getName());
			mp.put("pId", repositoryProduct.getPid());
			r.add(mp);

		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->添加
	@RequestMapping("addSpecialManage")
	@ResponseBody
	public void AddSpecialManage(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String description = request.getParameter("description");
		String[] classesIds = request.getParameterValues("classesIds");
		String pid = request.getParameter("pid");
		String classesId = "";
		if (classesIds != null && classesIds.length > 0) {
			for (int i = 0; i < classesIds.length; i++) {
				classesId += classesIds[i] + ",";
			}
		}
		RepositoryProduct repository = null;

		// 新增
		if ("0".equals(id)) {
			repository = new RepositoryProduct();
		} else {
			repository = publicService.findRepositoryProduct(Integer.parseInt(id));
		}

		repository.setName(name);
		repository.setDescription(description);
		// repository.setPreferential(new BigDecimal(preferential));
		repository.setStatus(0);
		repository.setClassesIds(classesId);
		repository.setPid(Integer.valueOf(pid));

		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		// 新增
		if ("0".equals(id)) {
			String createTime = DateUtils.getDateTime();
			repository.setCreateTime(createTime);
			try {
				baseService.saveRepositoryProduct(repository);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【新增】【知识库产品表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【新增】【知识库产品表】成功！", 0);
			}

		} else {
			// 修改
			try {
				baseService.editRepositoryProduct(repository);
			} catch (Exception e) {
				this.log(user.getId(), "general_data", null, null,
						"【" + user.getNickname() + "】【修改】【知识库产品表】 失败！请检查数据是否正确！", 1);
				logTime = 1;
				e.printStackTrace();
			}
			if (logTime == 0) {
				this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【修改】【知识库产品表】成功！", 0);
			}

		}

		String result = formatToJson(repository);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->更新
	@RequestMapping("specialManageUpdate")
	public void toSpecialManageUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		RepositoryProduct repository = publicService.findRepositoryProduct(id);

		LinkedHashMap<String, Object> repositoryList = new LinkedHashMap<String, Object>();
		repositoryList.put("id", repository.getId());
		repositoryList.put("name", repository.getName());
		repositoryList.put("description", repository.getDescription());
		repositoryList.put("parentId", repository.getPid());
		repositoryList.put("classesIds", repository.getClassesIds());

		if (repository.getPid() == 0) {
			repositoryList.put("parentName", "根目录");
		} else {
			RepositoryProduct Parent = publicService.findRepositoryProduct(repository.getPid());
			if (Parent.getName().equals(repository.getName())) {
				repositoryList.put("parentName", "根目录");
			} else {
				repositoryList.put("parentName", Parent.getName());
			}
		}

		String result = formatToJson(repositoryList);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->删除
	@RequestMapping("specialManageDel")
	public void toSpecialManageDel(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Integer id = Integer.parseInt(request.getParameter("id"));
		List<Integer> r = new ArrayList<Integer>();
		int count = 0;
		int logTime = 0;
		User user = publicService.findUser((Integer) request.getSession().getAttribute("userid"));

		try {
			RepositoryProduct repository = publicService.findRepositoryProduct(id);
			HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
			queryParams.put("%,productDetail", repository.getId() + ",");
			count = payService.getProjectCount(queryParams);
			if (count == 0) {
				baseService.deleteRepositoryProduct(repository);
			}
		} catch (Exception e) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【知识库产品表】 失败！请检查数据是否正确！",
					1);
			logTime = 1;
			e.printStackTrace();
		}
		if (logTime == 0) {
			this.log(user.getId(), "general_data", null, null, "【" + user.getNickname() + "】【删除】【知识库产品表】成功！", 0);
		}

		r.add(count);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->专题数据
	@RequestMapping("querySpecialDataList")
	@ResponseBody
	public void querySpecialDataList(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Integer pageSize = 15;
		Integer pageNum = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		String classZh = request.getParameter("classZh");
		String searchType = request.getParameter("searchType");
		Integer id = Integer.parseInt(request.getParameter("id"));
		HashMap<String, Object> m = new HashMap<String, Object>();
		HashMap<String, Object> search = new HashMap<String, Object>();
		RepositoryProduct repository = publicService.findRepositoryProduct(id);
		String queryStr = "";
		String classesIds = "";

		classesIds += repository.getClassesIds();

		// 查询子节点数据
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("=,pid", id);
		List<RepositoryProduct> repositoryProducts = publicService.getRepositoryProduct(queryParams, 1,
				publicService.getRepositoryProductCount(queryParams));
		if (repositoryProducts != null && repositoryProducts.size() > 0) {
			for (int i = 0; i < repositoryProducts.size(); i++) {
				String classId = repositoryProducts.get(i).getClassesIds();
				String query = "";
				if (StringUtils.isNotEmpty(classId)) {
					classesIds += classId;
					String[] classesIdSp = classId.split(",");
					query += "(";
					for (int j = 0; j < classesIdSp.length; j++) {
						Classes classes = publicService.findClasses(Integer.valueOf(classesIdSp[j]));
						query += "$type:" + classes.getNameEn();
						if (j != classesIdSp.length - 1) {
							query += " OR ";
						}
					}
					query += ")";

					if (StringUtils.isNotEmpty(repositoryProducts.get(i).getSearchExpression())) {
						query = "(" + query + " " + repositoryProducts.get(i).getSearchExpression() + ")";
					}

					if (StringUtils.isNotEmpty(repositoryProducts.get(i).getSearchExpressionAdditional())) {
						query = "(" + query + " " + repositoryProducts.get(i).getSearchExpressionAdditional() + ")";
					}

					if (i != repositoryProducts.size() - 1) {
						query += " OR ";
					}
					queryStr += query;
				}

			}
		}
		if (StringUtils.isNotEmpty(queryStr)
				&& queryStr.substring(queryStr.length() - 4, queryStr.length()).equals(" OR ")) {
			queryStr = queryStr.substring(0, queryStr.length() - 4);
		}
		List<String> classList = new ArrayList<String>();
		// 根节点数据
		if (StringUtils.isNotEmpty(repository.getClassesIds())) {
			String[] classesIdSp = repository.getClassesIds().split(",");
			String str = "";
			String query2 = "";
			if (StringUtils.isNotEmpty(queryStr)) {
				queryStr = "(" + queryStr + " OR ";
				str = ")";
			}
			query2 += "(";
			for (int j = 0; j < classesIdSp.length; j++) {
				Classes classes = publicService.findClasses(Integer.valueOf(classesIdSp[j]));
				query2 += "$type:" + classes.getNameEn();
				if (j != classesIdSp.length - 1) {
					query2 += " OR ";
				}

			}
			query2 += ")";

			if (StringUtils.isNotEmpty(repository.getSearchExpression())) {
				query2 = "(" + query2 + " " + repository.getSearchExpression() + ")";
			}

			if (StringUtils.isNotEmpty(repository.getSearchExpressionAdditional())) {
				query2 = "(" + query2 + " " + repository.getSearchExpressionAdditional() + ")";
			}

			queryStr += query2 + str;

		}

		if (StringUtils.isNotEmpty(classesIds)) {
			String[] classesIdSp = classesIds.split(",");
			for (int i = 0; i < classesIdSp.length; i++) {
				Classes classes = publicService.findClasses(Integer.valueOf(classesIdSp[i]));
				if (!classList.contains(classes.getNameZh())) {
					classList.add(classes.getNameZh());
				}
			}
			m.put("classList", classList);
			m.put("classZh", classZh);
			// 拼接检索条件
			if (!queryParam.equals("-1") && StringUtils.isNotEmpty(text)) {
				if (StringUtils.isNotEmpty(searchType) && "1".equals(searchType)) {
					queryStr += " AND $" + queryParam + ":" + '"' + text + '"';
				} else {
					queryStr += " AND $" + queryParam + ":" + text;
				}

			}
			if (StringUtils.isNotEmpty(classZh)) {
				queryStr += " AND $classZh:" + classZh;
			}

			search = searchService.search(queryStr, null, null, new String[] { "id", "classZh", "classEn",
					"create_user_id", "classes_id", "title", "create_time", "status" }, null, pageNum, pageSize);
			if (Integer.parseInt(search.get("count") + "") > 0) {
				List<Map<String, Object>> object = (List<Map<String, Object>>) search.get("data");
				for (Map<String, Object> map : object) {

					Integer create_user_id = ((List<Integer>) map.get("create_user_id")).get(0);
					User upUser = publicService.findUser(create_user_id);
					map.put("create_user", upUser.getNickname());
				}

			}

		} else {
			search.put("count", 0);
			m.put("classList", "");
		}
		m.put("search", search);
		String resultString = formatToJson(m);
		super.pringWriterToPage(resultString, "application/json", response);

	}

	// 知识库应用管理 -->专题管理 -->数据删除(只是不检索改条数据)
	@RequestMapping("applicationSpecialDataDeteleMethod")
	public void toApplicationSpecialDataDeteleMethod(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String id = request.getParameter("id");

		Integer ztreeId = Integer.parseInt(request.getParameter("ztreeId"));
		RepositoryProduct repository = publicService.findRepositoryProduct(ztreeId);
		String searchExpressionAdditional = repository.getSearchExpressionAdditional();
		if (StringUtils.isNotEmpty(searchExpressionAdditional)) {
			if (searchExpressionAdditional.contains("$id:" + id)) {
				searchExpressionAdditional = searchExpressionAdditional.replace("OR $id:" + id, "NOT $id:" + id);
			} else {
				searchExpressionAdditional = searchExpressionAdditional + " NOT $id:" + id;
			}

		} else {
			searchExpressionAdditional = " NOT $id:" + id;
		}
		repository.setSearchExpressionAdditional(searchExpressionAdditional);

		int logTime = 0;
		try {
			baseService.editRepositoryProduct(repository);
		} catch (Exception e) {
			logTime = 1;
			e.printStackTrace();
		}
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		returns.put("data", logTime);
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->数据撤回(1.从solr删除，2.改回状态为0)
	@RequestMapping("applicationSpecialDataRecall")
	public void toApplicationSpecialDataRecall(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String classesEn = request.getParameter("classesEn");
		String classesId = request.getParameter("classesId");
		String idString = request.getParameter("id");

		String[] ids = new String[1];
		ids[0] = idString;

		Integer departmentid = (Integer) request.getSession().getAttribute("userid");
		User user = publicService.findUser(departmentid);
		Classes classes = publicService.findClasses(Integer.parseInt(classesId));
		Map<String, Object> aDynamicData = null;
		aDynamicData = dynamicService.findDynamicData(classesEn, idString);
		String updateUserId = departmentid.toString();
		String status = "0";
		Double version = Double.valueOf(aDynamicData.get("version").toString()) + 1;
		String updateTime = DateUtils.getDateTime();
		String dataSource = "1";
		int logTime = 0;
		try {
			dynamicService.deleteIndex(ids);
			HashMap<String, Object> data = new HashMap<String, Object>();
			aDynamicData.remove("updateTime");
			aDynamicData.remove("updateUserId");
			aDynamicData.remove("status");
			aDynamicData.remove("version");
			aDynamicData.remove("id");
			aDynamicData.remove("createTime");
			aDynamicData.remove("submitTime");
			aDynamicData.remove("createUserId");
			aDynamicData.remove("submitUserId");
			aDynamicData.remove("dataSource");
			aDynamicData.remove("classesId");
			aDynamicData.remove("updateOrgId");
			aDynamicData.remove("createOrgId");
			aDynamicData.remove("submitOrgId");
			for (Object key : aDynamicData.keySet()) {
				data.put(key.toString(), aDynamicData.get(key));
			}

			dynamicService.editDynamicData(classesEn, data, updateTime, updateUserId, status, version.toString(),
					idString);
			// 获取服务器地址
			String saveVersion = XxlConfClient.get("dal.store.is.version", "");
			if ("true".equals(saveVersion)) {
				dynamicService.addDynamicDataVersion(classesEn, data, updateTime, updateUserId, status,
						version.toString(), classesId, dataSource, idString);
			}
		} catch (Exception e) {
			this.log(user.getId(), "data", classesId, idString, "【" + user.getNickname() + "】【修改】知识【"
					+ classes.getNameZh() + "】库ID为：【" + idString + "】的数据失败！请检查参数是否正确！", 1);
			logTime = 1;
			e.printStackTrace();
		}
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		returns.put("data", logTime);
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识库应用管理 -->专题管理 -->自定义数据查询
	@RequestMapping("queryApplicationClassDataList")
	@ResponseBody
	public void queryApplicationClassDataList(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		Integer pageSize = 15;
		Integer pageNum = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		String classZh = request.getParameter("classZh");
		String searchType = request.getParameter("searchType");
		Integer classesId = Integer.parseInt(request.getParameter("classesId"));
		HashMap<String, Object> m = new HashMap<String, Object>();
		HashMap<String, Object> search = new HashMap<String, Object>();
		String queryStr = "";
		if (classesId == 0) {
			queryStr = "*:*";
		} else {
			Classes classes = publicService.findClasses(Integer.valueOf(classesId));
			queryStr = "$type:" + classes.getNameEn();
		}

		if (!queryParam.equals("-1") && StringUtils.isNotEmpty(text)) {
			if (StringUtils.isNotEmpty(searchType) && "1".equals(searchType)) {
				queryStr += " AND $" + queryParam + ":" + '"' + text + '"';
			} else {
				queryStr += " AND $" + queryParam + ":" + text;
			}

		}
		search = searchService.search(queryStr, null, null, new String[] { "id", "classZh", "classEn", "create_user_id",
				"classes_id", "title", "create_time", "status" }, null, pageNum, pageSize);
		if (Integer.parseInt(search.get("count") + "") > 0) {
			List<Map<String, Object>> object = (List<Map<String, Object>>) search.get("data");
			for (Map<String, Object> map : object) {
				Integer create_user_id = ((List<Integer>) map.get("create_user_id")).get(0);
				User upUser = publicService.findUser(create_user_id);
				map.put("create_user", upUser.getNickname());
			}

		}
		m.put("search", search);
		String resultString = formatToJson(m);
		super.pringWriterToPage(resultString, "application/json", response);

	}

	// 知识库应用管理 -->专题管理 -->数据添加
	@RequestMapping("applicationSpecialDataAddMethod")
	public void toApplicationSpecialDataAddMethod(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 勾选内容
		Integer ztreeId = Integer.parseInt(request.getParameter("ztreeId"));
		RepositoryProduct repository = publicService.findRepositoryProduct(ztreeId);
		String searchExpressionAdditional = repository.getSearchExpressionAdditional();
		String[] ids = request.getParameterValues("ids");
		if (ids != null && ids.length > 0) {
			for (int i = 0; i < ids.length; i++) {

				if (StringUtils.isNotEmpty(searchExpressionAdditional)) {
					if (searchExpressionAdditional.contains("$id:" + ids[i])) {
						searchExpressionAdditional = searchExpressionAdditional.replace("NOT $id:" + ids[i],
								"OR $id:" + ids[i]);
					} else {
						searchExpressionAdditional += " OR $id:" + ids[i];
					}
				} else {
					searchExpressionAdditional = " OR $id:" + ids[i];
				}
			}
		}

		repository.setSearchExpressionAdditional(searchExpressionAdditional);

		int logTime = 0;
		try {
			baseService.editRepositoryProduct(repository);
		} catch (Exception e) {
			logTime = 1;
			e.printStackTrace();
		}
		LinkedHashMap<String, Object> returns = new LinkedHashMap<String, Object>();
		returns.put("data", logTime);
		String result = formatToJson(returns);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

}
